package me.ingxin.android.sample.lego

import android.app.Application
import android.content.Context
import android.content.res.AssetManager
import android.content.res.Configuration
import android.content.res.Resources
import me.ingxin.android.router.ComponentManager
import me.ingxin.android.router.Router
import me.ingxin.android.router.annotaions.App

/**
 * Created by ingxin on 2022/4/26
 */
@App
class MyApplication : Application() {

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        ComponentManager.instance.attachBaseContext(this, base)
    }

    override fun onCreate() {
        super.onCreate()
        Router.enableLog(true)
        ComponentManager.instance.onCreate(this)
    }


    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        ComponentManager.instance.onConfigurationChanged(this, newConfig)
    }

    override fun onLowMemory() {
        super.onLowMemory()
        ComponentManager.instance.onLowMemory(this)
    }

    override fun onTrimMemory(level: Int) {
        super.onTrimMemory(level)
        ComponentManager.instance.onTrimMemory(this, level)
    }

    override fun getResources(): Resources? {
        val re = super.getResources()
        return ComponentManager.instance.getResources(re)
    }

    override fun getAssets(): AssetManager? {
        val ass = super.getAssets()
        return ComponentManager.instance.getAssets(ass)
    }


}